package com.bbjob.mvc.advice;

import javax.servlet.http.HttpServletRequest;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.client.ResourceAccessException;

import com.bbjob.dto.Result;

@RestControllerAdvice(basePackages="com.bbjob.controller")
@ResponseBody
public class GlobalExceptionHandler {
	@ExceptionHandler(value=Exception.class)  
	@ResponseStatus(code=HttpStatus.INTERNAL_SERVER_ERROR)
	public Result allExceptionHandler(HttpServletRequest request,  
            Exception exception) throws Exception  
    {  
        exception.printStackTrace();
        System.out.println("我报错了："+exception.getLocalizedMessage());
        System.out.println("我报错了："+exception.getCause());
        System.out.println("我报错了："+exception.getSuppressed());
        System.out.println("我报错了："+exception.getMessage());
        System.out.println("我报错了："+exception.getStackTrace());
        return new Result(500, "服务器异常，请联系管理员");
    }
	@ExceptionHandler(value=ResourceAccessException.class)  
	@ResponseStatus(code=HttpStatus.NOT_FOUND)
	public Result ResourceAccessExceptionHandler(HttpServletRequest request,  
            Exception exception) throws Exception  
    {  
        exception.printStackTrace();
        System.out.println("我报错了："+exception.getLocalizedMessage());
        System.out.println("我报错了："+exception.getCause());
        System.out.println("我报错了："+exception.getSuppressed());
        System.out.println("我报错了："+exception.getMessage());
        System.out.println("我报错了："+exception.getStackTrace());
        return new Result(404, exception.getMessage());
    }
	
}
